package com.chookss.mine.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.TextView;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.chookss.R;
import com.chookss.mine.entity.MyViedeoEntity;
import com.chookss.mine.personal.MyMoreVediosActivity;
import com.chookss.tools.GridSpacingItemDecoration;
import com.chookss.tools.Utils;
import com.chookss.view.DrawableTextView;

import java.util.List;

import io.reactivex.annotations.Nullable;

public class MyVideoListAdapter extends BaseQuickAdapter<MyViedeoEntity, BaseViewHolder> {
   private Context context;
   private int type;
   private String employeeCode;
    private GridSpacingItemDecoration gridSpacingItemDecoration;
    public MyVideoListAdapter(int layoutResId, Context context, @Nullable List<MyViedeoEntity> data,int type,String employeeCode) {
        super(layoutResId, data);
        this.context=context;
        this.employeeCode=employeeCode;
        this.type=type;
        gridSpacingItemDecoration = new GridSpacingItemDecoration(3, Utils.dip2px(context, 6), false);
    }

    @Override
    protected void convert(BaseViewHolder helper, MyViedeoEntity item) {
        TextView tvTitle = helper.getView(R.id.tvTitle);
        RecyclerView rv = helper.getView(R.id.rvView);
        DrawableTextView tvMore = helper.getView(R.id.tvMore);
        tvTitle.setText(item.getCollectionsName());
        GridLayoutManager gridLayoutManager1 = new GridLayoutManager(context, 3);
        rv.setLayoutManager(gridLayoutManager1);
        if (rv.getItemDecorationCount() == 0) {
            rv.addItemDecoration(gridSpacingItemDecoration);
        }
        MyVideoAdapter adapter=null;
        if(item.getVideoList().size()>6){
             adapter = new MyVideoAdapter(R.layout.item_my_video, context, item.getVideoList().subList(0,6),"2",type);
        }else{
             adapter = new MyVideoAdapter(R.layout.item_my_video, context, item.getVideoList(),"2",type);
        }
        rv.setAdapter(adapter);
        if(item.getVideoList().size()>=6&&!Utils.isNull(item.getCollectionsCode())){
            tvMore.setVisibility(View.VISIBLE);
        }else{
            tvMore.setVisibility(View.GONE);
        }
        tvMore.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(context, MyMoreVediosActivity.class);
                intent.putExtra("employeeCode",employeeCode);
                intent.putExtra("videoCollectionsCode",item.getCollectionsCode());
                intent.putExtra("videoCollectionsName",item.getCollectionsName());
                context.startActivity(intent);
            }
        });
    }
}
